figure.SensorAzucar = new Class({
    Extends: figure.Dial,

    initialize: function(id, css, value, unit, min, capacity, step, wishConcentration) {
        this.parent(id, css, value, unit, min, capacity, step);
        this.wishConcentration = wishConcentration;
        this.start = false;
    },

    addEvents: function() {
        var controlElement = this.controlElement;
        controlElement.on('decrease', function decrease(event, etanol, basculaFermentacion, sugar, tank, v2, v3) {
            if (figure.stopAnimation) {
                window.setTimeout(function() { decrease(event, etanol, basculaFermentacion, sugar, tank, v2, v3) }, figure.speed);
                return;
            }
            if (sugar.start) {
                var valueAsInt = parseInt(basculaFermentacion.controlElement[0].value);
                var maxValueAsInt = parseInt(basculaFermentacion.controlElement[0].max);
                var value = controlElement[0].value;
                if (value > sugar.wishConcentration[1]) {
                    if (valueAsInt == maxValueAsInt) {
                        value -= 0.1;
                        value = value.toFixed(1);
                        controlElement[0].value = value;
                        controlElement.trigger('change');
                    }
                    if (value == sugar.wishConcentration[0]) {
                        tank.drawCrossLine('2', 'green');
                        tank.unifyLines('2', 'green');
                        v2.draw('green');
                    }
                    if (value == sugar.wishConcentration[1]) {
                        tank.drawCrossLine('3', 'green');
                        tank.unifyLines('3', 'green');
                        figure.pipesStatus['levaduraStart'] = false;
                        figure.pipesStatus['levaduraEnd'] = false;
                        v3.draw('green');
                    }
                }
            }
            window.setTimeout(function() { decrease(event, etanol, basculaFermentacion, sugar, tank, v2, v3) }, figure.speed);
        });
    },

    getValue: function() {
        return this.element.text();
    }

});
